package com.qsmx.store.app.main.service;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatSpinner;
import android.support.v7.widget.AppCompatTextView;
import android.view.View;

import com.qsmx.store.app.R;
import com.qsmx.store.app.R2;
import com.qsmx.store.app.event.SetShowMaxEvent;
import com.qsmx.store.app.fustion.FustionTag;
import com.qsmx.store.app.main.home.HomeDelegate;
import com.qsmx.store.core.delegates.AtmosDelegate;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

public class ServiceCoinDelegate extends AtmosDelegate {

    private String pageType;

    @BindView(R2.id.tv_coin_out_type)
    AppCompatTextView tvCoinOutType = null;
    @BindView(R2.id.sp_coin_out_type)
    AppCompatSpinner spCoinOutType = null;
    @BindView(R2.id.tv_coin_out_num)
    AppCompatTextView tvCoinOutNum = null;
    @BindView(R2.id.tv_title)
    AppCompatTextView tvTitle = null;

    @OnClick(R2.id.lin_content)
    void onPageClick() {
        EventBus.getDefault().post(new SetShowMaxEvent(new Bundle()));
    }

    @OnClick(R2.id.iv_back)
    void onBack() {
        getParentDelegate().getSupportDelegate().pop();
    }

    @OnClick(R2.id.iv_home)
    void onHome() {
        getParentDelegate().getSupportDelegate().popTo(HomeDelegate.class, false);
    }

    public static ServiceCoinDelegate create(String type) {

        final Bundle args = new Bundle();
        args.putString(FustionTag.COIN_PAGE_TYPE, type);
        final ServiceCoinDelegate delegate = new ServiceCoinDelegate();
        delegate.setArguments(args);
        return delegate;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Bundle args = getArguments();
        if (args != null) {
            pageType = args.getString(FustionTag.COIN_PAGE_TYPE);
        }
    }


    @Override
    public Object setLayout() {
        return R.layout.delegate_service_get_coin;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {

        if (pageType.equals("out")) {
            tvCoinOutType.setVisibility(View.VISIBLE);
            tvCoinOutNum.setText(getString(R.string.service_get_coin_num));
            spCoinOutType.setVisibility(View.VISIBLE);
            tvTitle.setText(getString(R.string.service_get_coin));
        } else {
            tvCoinOutType.setVisibility(View.GONE);
            tvCoinOutNum.setText(getString(R.string.service_save_coin_num));
            spCoinOutType.setVisibility(View.GONE);
            tvTitle.setText(getString(R.string.service_save_coin));
        }

    }
}
